package com.loan.web.api;

import com.loan.entity.Repayment;
import com.loan.entity.ResponseResult;
import com.loan.group.GetAppointRepayment;
import com.loan.group.GetRepaymentAllInfoGroup;
import com.loan.group.RepaymentPayGroup;
import com.loan.service.RepaymentService;
import com.loan.vo.RepaymentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: RepaymentController
 * @Author: wYin
 * @Date: 2022/1/18 18:22
 */
@RestController
@RequestMapping("/api/repayment")
public class RepaymentController {
    @Autowired
    private RepaymentService repaymentService;
    /**
     * 传入数据：客户id、还款表id、合同id、还款方式id、是否支付罚金(y||n)
     *   根据传入的客户id和还款表id以及合同id进行用户还款信息的修改
     *   过程：检查当前用户还款时间是否逾期（逾期则相应的状态为y)-逾期则合同表中逾期次数+1（如果愿意交取罚息，则相应的逾期次数不增加）
     *   更新数据：是否逾期（比较约定还款时间和实际还款时间）、实际还款时间、还款方式、（如果逾期是否交取罚金，交取罚金则相应的逾期次数不+1）、修改合同表中剩余的还款金额（合同表欠款金额-支付金额）
     * @Param: [repayment]
     * @Return: com.loan.entity.ResponseResult<java.lang.Void>
     * @Author: wYin
     * @Date: 2022/1/18 18:23
     */
    @PostMapping("update")
    public ResponseResult<Void> update(@RequestBody @Validated(RepaymentPayGroup.class) Repayment repayment){
        boolean flag = repaymentService.repaymentUpdate(repayment);
        if(flag){
            return new ResponseResult<>(200,"还款成功");
        }
        return ResponseResult.FAIL;
    }

    /**
     * @Desc: 接收员工id和合同id
     * @Param: [repayment]
     * @Return: java.util.List<com.loan.entity.Repayment>
     * @Author: wYin
     * @Date: 2022/1/22 18:10
     */
    @PostMapping("/getAppointRepayment")
    public ResponseResult<List<Repayment>> getAppointRepayment(@RequestBody @Validated(GetAppointRepayment.class) Repayment repayment){
        List<Repayment> list = repaymentService.getAppointRepayment(repayment);
        return new ResponseResult<>(list);
    }

    /**
     * @Desc: 根据传入的还款id、客户id、合同id得到用户信息、合同信息、违期罚息
     * @Param: [repayment]
     * @Return: com.loan.entity.ResponseResult<com.loan.vo.RepaymentVO>
     * @Author: wYin
     * @Date: 2022/1/23 17:35
     */
    @PostMapping("/getRepaymentAllInfo")
    public ResponseResult<RepaymentVO> getRepaymentAllInfo(@RequestBody @Validated(GetRepaymentAllInfoGroup.class) Repayment repayment){
        RepaymentVO repaymentAllInfo = repaymentService.getRepaymentAllInfo(repayment);
        return new ResponseResult<>(repaymentAllInfo);
    }

}
